package com.hzhr.iot.user.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.user.controller.base.BaseController;
import com.hzhr.iot.user.model.company_basicInfo.Company_BasicInfoGetModel;
import com.hzhr.iot.user.model.company_basicInfo.Company_BasicInfoPostModel;
import com.hzhr.iot.user.model.company_basicInfo.Company_BasicInfoPutModel;
import com.hzhr.iot.user.service.Company_BasicInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "Company_BasicInfo", description = "公司的基础信息")
@RestController
@RequestMapping(value = "")
public class Company_BasicInfoController extends BaseController {
    @Autowired
    Company_BasicInfoService company_basicInfoService;

    //region /companys/basic-infos PUT
    //region swagger响应码 : put
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询公司  \n----异常说明 : 公司不存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : put
    @ApiOperation(value="公司创始人更新其所创建的公司的基本信息", notes="公司创始人更新其所创建的公司的基本信息  \n简介 : 更新公司信息  \n步骤 :  \n1. 查询公司 : (√)  \n 查询登录人所创建的公司(COMPANY)company_1，如果company_1不存在，抛出异常201；  \n2. 更新基本信息 : (√)  \n 根据body更新company_1的基本信息；  \n3. 返回信息 : (√)  \n 根据条件参数查询更新结果，组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : put
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })

    //endregion
    //region 请求 : put
    @RequestMapping(value = "/companys/basic-infos", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<Company_BasicInfoGetModel> put(@RequestParam @ApiIgnore Map<String, Object> query,
                                                         @RequestBody Company_BasicInfoPutModel body) throws ServiceException {
        Company_BasicInfoGetModel responseBody = company_basicInfoService.put(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
    //region /companys/basic-infos POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证登录人类型  \n----异常说明 : 登录人不是游离用户，无法进行操作  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证公司名称  \n----异常说明 : 公司名称已存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="用户创建公司", notes="用户创建公司  \n简介 : 创建公司；创建同名顶级部门；更新登录用户信息  \n步骤 :  \n1. 验证登录用户类型 : (√)  \n 根据登录人的userId查询用户(USER)user_1，如果user_1.type不是游离用户，抛出异常201；  \n2. 验证公司名称 : (√)  \n 验证是否存在某个公司(COMPANY)的name与body.name相同，如果存在，则抛出异常202；  \n3. 创建公司 : (√)  \n 根据body创建公司(COMPANY)company_1，并且同时设置以下属性：  \n (1) company_1.resourceCode = '0'；  \n4. 更新公司的资源代码 : (√)  \n 设置company_1.resourceCode；  \n (1) company_1.resourceCode设置规则：将company_1.id左补零至4位字符串str_1, company_1.resourceCode = '01' + str_1；  \n5. 创建同名顶级部门 : (√)  \n 在company_1下创建同名的部门(DEPT)dept_1，并且同时设置以下属性：  \n (1) dept_1.code = company_1.id + '-01'；  \n (2) dept_1.level = 1；  \n (3) dept_1.parentId = 0；  \n (3) dept_1.resourceCode = company_1.resourceCode + '01'；  \n6. 更新登录用户信息 : (√)  \n 更新user_1的以下属性：  \n (1) user_1.type设置为公司创始人；  \n (2) user_1.companyId = company_1.id；  \n (3) user_1.deptId = dept_1.id；  \n (4) user_1.resourceCode = company_1.resourceCode；  \n7. 返回信息 : (√)  \n 根据条件参数查询创建结果，组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/companys/basic-infos", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<Company_BasicInfoGetModel> post(@RequestParam @ApiIgnore Map<String, Object> query,
                                                         @RequestBody Company_BasicInfoPostModel body) throws ServiceException {
        Company_BasicInfoGetModel responseBody = company_basicInfoService.post(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
    //region /companys/basic-infos GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="用户查询其创建的公司的基本信息", notes="用户查询其创建的公司的基本信息  \n简介 : 查询公司信息  \n步骤 :  \n1. 查询公司信息 : (√)  \n 查询登录人所创建的公司(COMPANY)；  \n2. 返回信息 : (√)  \n 根据条件参数和查询到的结果组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/companys/basic-infos", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<Company_BasicInfoGetModel> get(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        Company_BasicInfoGetModel responseBody = company_basicInfoService.get(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
    //region /v1/companys/basic-infos GET
    //region swagger响应码 : get1
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get1
    @ApiOperation(value="用户查询其所属的公司的基本信息", notes="用户查询其所属的公司的基本信息  \n简介 : 查询公司信息  \n步骤 :  \n1. 查询公司信息 : (√)  \n 查询登录人所属的公司(COMPANY)；  \n2. 返回信息 : (√)  \n 根据条件参数和查询到的结果组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : get1
    @RequestMapping(value = "/v1/companys/basic-infos", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<Company_BasicInfoGetModel> get1(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        Company_BasicInfoGetModel responseBody = company_basicInfoService.get1(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}
















































































































































































































































































































































































